package com.heima.article.feign;

import com.heima.apis.article.IArticleClient;
import com.heima.article.service.ApArticleContentService;
import com.heima.article.service.ApArticleService;
import com.heima.article.service.ArticleConfigService;
import com.heima.model.article.dtos.ArticleCommentDto;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.wemedia.dtos.WmNewsCommentDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import thread.WmThreadLocalUtil;

@RestController
public class ArticleClient implements IArticleClient {
    @Autowired
    private ApArticleService apArticleService;
    @Autowired
    private ArticleConfigService articleConfigService;

    /**
     * 保存文章到app
     *
     * @param articleDto
     * @return
     */
    @Override
    @PostMapping("/api/v1/article/save")
    public ResponseResult save(@RequestBody ArticleDto articleDto) {
        return apArticleService.saveArticle(articleDto);
    }

    @Override
    @PostMapping("/api/v1/comment/commentList")
    public PageResponseResult findNewsComments(@RequestBody ArticleCommentDto dto) {
        return apArticleService.find_news_comments(dto);
    }

    @Override
    @PostMapping("/api/v1/comment/status")
    public ResponseResult update_comment_status(@RequestBody WmNewsCommentDto dto) {
        return articleConfigService.update_comment_status(dto);
    }

    /**
     * 自媒体端图文统计
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/api/v1/statistics/newsDimension")
    public ResponseResult newsDimension(@RequestBody WmNewsPageReqDto dto) {
        return apArticleService.newsDimension(dto);
    }

    /**
     * 发布详情统计
     *
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/api/v1/statistics/newsPage")
    public PageResponseResult newsPage(@RequestBody WmNewsPageReqDto dto) {
        return apArticleService.newsPage(dto);
    }

    @Override
    @PostMapping("(/api/v1/comment/isComment")
    public Boolean isComment(Long articleId) {
        return articleConfigService.isComment(articleId);
    }

    @Override
    @PostMapping("(/api/v1/statistics/newsDetail")
    public ResponseResult newsDetail(WmNewsPageReqDto dto) {
        return apArticleService.newsDetail(dto);
    }

    @Override
    @PostMapping("/api/v1/comment/manage/delCom")
    public void reduceComment(Long articleId) {
         apArticleService.reduceComment(articleId);
    }
}
